<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: pink;
        }
        .change {
            background-color: purple;
            color: #fff;
            font-size: 30px;
            margin-top: 100px;

        }
    </style>
</head>
<body>
    <div>文本</div>
    <script>
        var test = document.querySelector('div');
        test.onclick = function () {
            //我们可以通过修改元素的className更改元素的样式，适合于样式较多或者功能复杂的样式
            this.className = 'change';
        }
    </script>
</body>
</html>